#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTimer>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui_c.h>


QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

//udp
#include <stdio.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/socket.h>
#include "Ffmpeg_Decode.h"


#include <list>
#include <thread>
#include <utility>
#include <mutex>

//socket struct
typedef struct socket_info
{
    int serSocket;
    int numClient;
    sockaddr_in remoteAddr[10];
    //int nAddrLen[10];
    socklen_t nAddrLen[10];

}Socket_Udp_Server_Info;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    void ShowImage(cv::Mat& mat);
    QImage MatToQImage2(const cv::Mat &mat);
    ~MainWindow();


    void decode_show();

private slots:
    //void on_pushButton_open_clicked();

    void on_pushButton_play_clicked();

    void ReadFrame();

    void on_pushButton_pause_clicked();

    void udp_recv_func();
    void decode_show_func();


private:
    Ui::MainWindow *ui;


    cv::VideoCapture video;
    QTimer *timer;
    QTimer *timer1;
    QTimer *timer2;

    int fps;
    QString videofileName;
    std::string sfileName;

    //houlc
    bool is_play = false;
    int recv_width;
    int recv_height;
    int recv_channel;
    int recv_bufferSize;

    std::mutex mtx_list;
    std::list<std::pair<char*, int>> list_pbuff;
    
    std::mutex mtx_rgblist;
    std::list<Mat> list_matbuff;


    Ffmpeg_Decoder ffmpegobj;
    Socket_Udp_Server_Info * mSocketUdpServerInfo;

};
#endif // MAINWINDOW_H
